<!DOCTYPE html>

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>登陆测试</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>

<body>

<a href="https://api.weibo.com/oauth2/authorize?client_id=1518242831&response_type=code&redirect_uri=http://www.ppyeah.com/demo/index.htm">
	去授权
</a>

<form action="https://api.weibo.com/oauth2/access_token" method="post">
	<input type="hidden" id="code" name="code">
	<input type="hidden" id="client_id" name="client_id" value="1518242831">
	<input type="hidden" id="client_secret" name="client_secret" value="035e8535fa7a8e641e69e870e211df0d">
	<input type="hidden" id="grant_type" name="grant_type" value="authorization_code">
	<input type="hidden" id="redirect_uri" name="redirect_uri" value="http://www.ppyeah.com/demo/success.htm">
	<input type="submit" value="登陆">
	<input type="button" value="Ajax登陆">
</form>

	<script type="text/javascript">
	
		function ajaxLogin(){
			
			$.post(
				"https://api.weibo.com/oauth2/access_token",
				{
					code:$("code").val(),
					client_id:$("client_id").val(),
					client_secret:$("client_secret").val(),
					grant_type:$("grant_type").val(),
					redirect_uri:$("redirect_uri").val()
				},
				function(data){
					alert(data);
				}
			);
			
		}
		
		$(document).ready(function(){
			
			var code=getParameter("code");
			
			$("#code").val(code);
			
			alert(code);
			
		});
	
    	//获取指定请求参数的值
		function getParameter(name){ 
			var paramStr=location.search; 
			if(paramStr.length==0)return null; 
			if(paramStr.charAt(0)!='?')return null; 
			paramStr=unescape(paramStr); 
			paramStr=paramStr.substring(1); 
			if(paramStr.length==0)return null; 
			var params=paramStr.split('&'); 
			var p = null;
			for(var i=0;i<params.length;i++){
				if(params[i].indexOf(name) >= 0){           
					p = params[i].split('=');
					p = p[1];
				}
			}
			return p;
		}
   
    </script>

</body>


</html>


